from rest_framework.generics import ListAPIView
from rest_framework.viewsets import ModelViewSet

from apps.goods.models import GoodsChannel, GoodsChannelGroup, GoodsCategory
from apps.meiduo_admin.serializers.goods_channel import ChannelsSer, ChannelTypesSer, FirstCategorySer
from apps.meiduo_admin.utils.MeiduoPage import PageNum


class ChannelsViewSet(ModelViewSet):
    queryset = GoodsChannel.objects.all()
    serializer_class = ChannelsSer
    pagination_class = PageNum

class ChannelTypesView(ListAPIView):
    queryset = GoodsChannelGroup.objects.all()
    serializer_class = ChannelTypesSer


class FirstCategorySer(ListAPIView):
    queryset = GoodsCategory.objects.filter(parent__isnull=True)
    serializer_class = FirstCategorySer